﻿using Microsoft.AspNetCore.Mvc;
using Nacos.V2;
namespace BaseGrpcClient.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class NacosConfigController : ControllerBase
    {
        private readonly INacosConfigService _configService;

        public NacosConfigController(INacosConfigService configService)
        {
            _configService = configService;
        }

        // GET api/config?key=demo1
        [HttpGet]
        public async Task<string> Get([FromQuery] string key)
        {
            var res = await _configService.GetConfig(key, null, 5000);

            return string.IsNullOrWhiteSpace(res) ? "Not Found" : res;
        }
        [HttpPut("add")]
        public async Task<string> Add([FromQuery] string key, [FromQuery] string value)
        {

            var res = await _configService.PublishConfig(key, "DEFAULT_GROUP", value);

            return res.ToString();
        }
    }
}
